#pragma once

/* condition x is very likely true. */
#define likely(x) __builtin_expect((x), true)
/* condition x is very likely false. */
#define unlikely(x) __builtin_expect((x), false)

#include <stdarg.h>

inline void LOG_(bool terminate, const char* fmt, ...)
{
    std::string new_fmt;
    new_fmt += fmt;
    new_fmt += '\n';
    va_list args;
    va_start(args, fmt);
    vprintf(new_fmt.c_str(), args);
    va_end(args);
    if (terminate)
        exit(EXIT_FAILURE);
}
#if 0
#define LOG_INFO(fmt, ...) LOG_(false, fmt, ##__VA_ARGS__)
#define LOG_ERR(fmt, ...) LOG_(false, fmt, ##__VA_ARGS__)
#define LOG_FATAL(fmt, ...) LOG_(true, fmt, ##__VA_ARGS__)
#else
#define LOG_INFO(fmt, ...) 
#define LOG_ERR(fmt, ...)
#define LOG_FATAL(fmt, ...)
#endif